/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cconverter;

import java.awt.Color;
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.border.EmptyBorder;

/**
 *
 * @author SapunBoj
 */
public class ComboBoxRender extends JLabel implements ListCellRenderer {

    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        this.setOpaque(true);
        this.setText((String) value);
        this.setVerticalAlignment(CENTER);
        this.setHorizontalAlignment(LEADING);
        list.setFixedCellHeight(22);

        // add 2px left padding
        EmptyBorder a = new EmptyBorder(0, 2, 0, 0);
        this.setBorder(a);

        if (isSelected) {
            this.setBackground(Sets.focus);
            this.setForeground(Color.white);
        } else {
            this.setBackground(list.getBackground());
            this.setForeground(list.getForeground());
        }
        String cur = "";
        if(value.toString().length() > 3){
            cur = makeCur(value.toString().toLowerCase());
        }else if(value.toString().length() == 3){
            cur = value.toString().toLowerCase();
        }
        this.setIcon((Icon) new Flags().Flags(cur));
        return this;
    }

    public String makeCur(String big) {
        return big.substring(big.length() - 4, big.length() - 1);
    }
}
